<template>
  <div>
    <head-no-next :title="title"></head-no-next>
    <div class="flex_center">
      <div class="bodyContent">
        <loading v-if="isShowLoading"></loading>
        <div class="shopC_div flex flex_between" style="margin-top: 0.5rem" v-for="(shop,index) in shopList" v-if="!isShowLoading">
          <div class="shopC_img">
            <img style="border-radius: 20px" src="../components/personal/img/my_bg.png" v-if="shop.shop_logo == undefined || shop.shop_logo == null || shop.shop_logo == ''">
            <img :src="shop.shop_logo" v-if="shop.shop_logo != undefined && shop.shop_logo != null && shop.shop_logo != ''">
          </div>
          <div class=" shopC_content flex flex_column flex_around">
            <p style="font-weight: bold">{{shop.shop_name}}</p>
            <p style="font-size: 0.7rem;color: #777">{{shop.area_info +' '+ shop.address}}</p>
          </div>
          <mu-flex justify-content="center" align-items="center" class="shopC_radio" >
            <mu-radio style="margin-left: 16px" v-model="shop.is_default" value="1" label="" @click="changeRadio(shop,index)"></mu-radio>
          </mu-flex>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
    import HeadNoNext from "../../src/components/components/HeadNoNext";
    import Loading from "../../src/components/loading";

    export default {
      components: {
        Loading,
        HeadNoNext},
      name: "choose-shop",
      data(){
        return{
          isShowLoading:true,
          title:'选择店铺',
          aid:null,
          xcx_openid:'',
          wx_openid:'',
          token:'',
          shopList:''
        }
      },
      mounted(){
        this.aid = this.$route.query.aid || '';
        this.xcx_openid = this.$route.query.xcx_openid || '';
        this.wx_openid = this.$route.query.wx_openid || '';
        this.token = this.$route.query.token || '';
        if(this.isEmpty(this.aid) || (this.isEmpty(this.xcx_openid) && this.isEmpty(this.wx_openid))){
          this.$toast.warning('非法操作');
        } else {
          this.initList();
        }

      },
      methods:{
        initList(){
          this.yesS.chooseShop(
            {aid: this.aid, xcx_openid: this.xcx_openid,wx_openid:this.wx_openid,token:this.token}
          ).then(res => {
            this.isShowLoading = false
            this.shopList = res.data.shop_list;

          })
        },
        changeRadio(obj,index){
          for(var i=0;i<this.shopList.length;i++){
            this.shopList[i].is_default = '0';
          }
          var _slef = this;
          obj.is_default = '1';
          this.yesS.bindShop(
            {sid: obj.id, xcx_openid: this.xcx_openid,wx_openid:this.wx_openid,token:this.token}
          ).then(res => {
            console.log(res)
            //跳转到主页
            var info = res.data;
            if (!this.isEmpty(info)) {

              this.$router.push({path:'/qds/homepage',query:{xcx_openid:info.xcx_openid,wx_openid:info.wx_openid,sid:info.sid}})
            }
          })
        }
      }
    }
</script>

<style scoped>
  @import "../components/personal/css/shopChange.css";
</style>
